<template>
  <div>
    <van-nav-bar
      title="我的收货地址"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <van-address-list
      v-model="chosenAddressId"
      :list="address"
      default-tag-text="默认"
      @add="onAdd"
      @edit="onEdit"
    />
    <van-empty description="您还没有添加收货地址哦!" v-show="addressState">
      <van-button
        size="normal"
        type="danger"
        class="bottom-button"
        to="cart/paddress"
      >
        添加收货地址</van-button
      >
    </van-empty>
  </div>
</template>

<script>
import { Toast } from "vant";
export default {
  data() {
    return {
      chosenAddressId: "1",
      state: false,
      addressState: true,
      address: [],
    };
  },
  methods: {
    onAdd() {
      this.$router.replace({ path: "/cart/paddress" });
    },
    onEdit(item, index) {
      this.$router.replace({ path: "/cart/paddress" });
    },
    onClickLeft() {
      this.$router.go(-1);
    },
  },

  created() {
    let address = this.$store.getters.address;

    if (address.length == 0) {
      this.state = false;
      this.addressState = true;
    } else {
      this.address = address;
      this.state = true;
      this.addressState = false;
    }
  },
};
</script>

<style scoped>
.bottom-button {
  margin-top: 1rem;
  width: 3rem;
  height: 1rem;
}
</style>